<template>
	<view class="container">
		<!-- 状态栏占位 -->
		<view class="status-bar"></view>
		
		<!-- 头部 -->
		<view class="header">
			<view class="header-left" @click="goBack">
				<text class="back-icon">←</text>
			</view>
			<text class="header-title">维修管理</text>
			<view class="header-right"></view>
		</view>
		
		<!-- 维修单列表 -->
		<view style="padding: 12px 16px; background-color: #f5f5f5;">
			<view 
				v-for="(order, index) in workOrders" 
				:key="index"
				style="background: white; border-radius: 8px; padding: 16px; margin-bottom: 12px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);"
			>
				<view style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid #f0f0f0;">
					<view style="flex: 1;">
						<text style="display: block; font-size: 14px; font-weight: bold; color: #333; margin-bottom: 4px;">维修单号: {{ order.workNo }}</text>
						<text style="display: block; font-size: 12px; color: #666;">报修单号: {{ order.reportNo }}</text>
					</view>
					<view style="padding: 4px 12px; border-radius: 12px; font-size: 12px; background-color: #fff3e0; color: #ff9800;">
						<text>{{ order.statusName }}</text>
					</view>
				</view>
				
				<view style="display: flex; justify-content: space-between; font-size: 14px; color: #666; margin-bottom: 8px;">
					<text style="font-weight: 500;">开始时间</text>
					<text>{{ order.startTime || '-' }}</text>
				</view>
				
				<view style="display: flex; justify-content: space-between; font-size: 14px; color: #666; margin-bottom: 8px;">
					<text style="font-weight: 500;">结束时间</text>
					<text>{{ order.endTime || '-' }}</text>
				</view>
				
				<view style="display: flex; gap: 8px; margin-top: 12px;">
					<button style="flex: 1; height: 36px; font-size: 14px; border-radius: 6px; border: none; background-color: #409eff; color: white;" @click="viewOrderByIndex(index)">查看</button>
					<button v-if="order.status === 'PENDING_ASSIGN' || order.statusName === '待分配'" style="flex: 1; height: 36px; font-size: 14px; border-radius: 6px; border: none; background-color: #67c23a; color: white;" @click="assignWorkerByIndex(index)">指派</button>
					<button v-if="order.status === 'PENDING_CONFIRM' || order.statusName === '待确认'" style="flex: 1; height: 36px; font-size: 14px; border-radius: 6px; border: none; background-color: #67c23a; color: white;" @click="confirmOrderByIndex(index)">确认</button>
					<button v-if="order.status === 'PENDING_CONFIRM' || order.statusName === '待确认'" style="flex: 1; height: 36px; font-size: 14px; border-radius: 6px; border: none; background-color: #f56c6c; color: white;" @click="rejectConfirmByIndex(index)">拒绝确认</button>
					<button style="flex: 1; height: 36px; font-size: 14px; border-radius: 6px; border: none; background-color: #f56c6c; color: white;" @click="deleteOrderByIndex(index)">删除</button>
				</view>
			</view>
		</view>
		
		<!-- 空状态 -->
		<view class="empty-state" v-if="!loading && workOrdersLength === 0">
			<text class="empty-icon">📋</text>
			<text class="empty-text">暂无维修单</text>
		</view>
		
		<!-- 加载状态 -->
		<view class="loading-state" v-if="loading">
			<text class="loading-text">加载中...</text>
		</view>
		
		<!-- 维修单详情弹窗 -->
		<view style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 9999;" v-if="showDetailModal" @click="closeDetailModal">
			<view style="width: 90%; background-color: white; border-radius: 12px; overflow: hidden;" @click.stop>
				<view style="display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid #f0f0f0;">
					<text style="font-size: 16px; font-weight: bold; color: #333;">维修单详情</text>
					<text style="font-size: 24px; color: #999;" @click="closeDetailModal">×</text>
				</view>
				
				<view style="padding: 16px;">
					<view style="margin-bottom: 16px;">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">维修单号</text>
						<text style="font-size: 14px; color: #333;">{{ currentOrder.workNo }}</text>
					</view>
					
					<view style="margin-bottom: 16px;">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">报修单号</text>
						<text style="font-size: 14px; color: #333;">{{ currentOrder.reportNo }}</text>
					</view>
					
					<view style="margin-bottom: 16px;">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">状态</text>
						<text style="font-size: 14px; color: #333;">{{ currentOrder.statusName }}</text>
					</view>
					
					<view style="margin-bottom: 16px;" v-if="currentOrder.leaderId">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">负责人</text>
						<text style="font-size: 14px; color: #333;">{{ currentOrder.leaderName || currentOrder.leaderId }}</text>
					</view>
					
					<view style="margin-bottom: 16px;" v-if="currentOrder.assigneeId">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">维修人员</text>
						<text style="font-size: 14px; color: #333;">{{ currentOrder.assigneeName || currentOrder.assigneeId }}</text>
					</view>
					
					<view style="margin-bottom: 16px;">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">开始时间</text>
						<text style="font-size: 14px; color: #333;">{{ currentOrder.startTime || '未设置' }}</text>
					</view>
					
					<view style="margin-bottom: 16px;">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">结束时间</text>
						<text style="font-size: 14px; color: #333;">{{ currentOrder.endTime || '未设置' }}</text>
					</view>
					
					<view style="margin-bottom: 16px;" v-if="currentOrder.faultCause">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">故障原因</text>
						<text style="font-size: 14px; color: #333;">{{ currentOrder.faultCause }}</text>
					</view>
					
					<view style="margin-bottom: 16px;" v-if="currentOrder.countermeasure">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">处理措施</text>
						<text style="font-size: 14px; color: #333;">{{ currentOrder.countermeasure }}</text>
					</view>
					
					<view style="margin-bottom: 16px;" v-if="currentOrder.remark">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">备注</text>
						<text style="font-size: 14px; color: #333;">{{ currentOrder.remark }}</text>
					</view>
				</view>
				
				<view style="display: flex; border-top: 1px solid #f0f0f0;">
					<button style="flex: 1; height: 48px; font-size: 16px; border: none; border-radius: 0; background-color: #f5f5f5; color: #666;" @click="closeDetailModal">关闭</button>
				</view>
			</view>
		</view>
		
		<!-- 指派维修人员弹窗 -->
		<view style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 9999;" v-if="showAssignModal" @click="closeAssignModal">
			<view style="width: 80%; background-color: white; border-radius: 12px; overflow: hidden;" @click.stop>
				<view style="display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid #f0f0f0;">
					<text style="font-size: 16px; font-weight: bold; color: #333;">指派维修人员</text>
					<text style="font-size: 24px; color: #999;" @click="closeAssignModal">×</text>
				</view>
				
				<view style="padding: 16px;">
					<view style="margin-bottom: 16px;">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">维修单号</text>
						<text style="font-size: 14px; color: #333;">{{ currentOrder.workNo }}</text>
					</view>
					
					<view style="margin-bottom: 16px;">
						<text style="display: block; font-size: 14px; color: #666; margin-bottom: 8px;">指派给 <text style="color: #f56c6c;">*</text></text>
						<picker @change="onWorkerChange" :value="workerIndex" :range="workers" range-key="name">
							<view style="border: 1px solid #dcdfe6; border-radius: 4px; padding: 10px; background-color: #fff;">
								<text style="font-size: 14px; color: #333;">{{ selectedWorker || '请选择维修人员' }}</text>
							</view>
						</picker>
					</view>
				</view>
				
				<view style="display: flex; border-top: 1px solid #f0f0f0;">
					<button style="flex: 1; height: 48px; font-size: 16px; border: none; border-radius: 0; background-color: #f5f5f5; color: #666;" @click="closeAssignModal">取消</button>
					<button style="flex: 1; height: 48px; font-size: 16px; border: none; border-radius: 0; background-color: #409eff; color: white;" @click="confirmAssign">确定</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { listWorkOrder, updateWorkOrder, delWorkOrder, getWorkOrder } from '@/api/repair/workOrder.js';
	import { listUser } from '@/api/system/user.js';
	import { allocatedUserList } from '@/api/system/role.js';
	import { getUserInfo } from '@/utils/auth.js';
	import permissionManager from '@/utils/permission.js';
	
	export default {
	data() {
		return {
			workOrders: [],
			workOrdersLength: 0,  // 添加一个单独的长度字段
			showAssignModal: false,
			showDetailModal: false,  // 详情弹窗
			currentOrder: {},
			workerIndex: 0,
			selectedWorker: '',
			selectedWorkerId: null,
			workers: [],
			loading: false
		}
	},
	onLoad() {
		console.log('页面onLoad');
	},
	
	onReady() {
		console.log('页面onReady - 开始加载数据');
		// 在页面完全渲染后加载数据
		this.loadWorkOrders();
		this.loadWorkers();
	},
	
	onShow() {
		console.log('页面onShow');
	},
	computed: {
		// 计算属性：获取维修单数量
		workOrdersCount() {
			return this.workOrders ? this.workOrders.length : 0;
		},
		// 计算属性：是否有数据
		hasData() {
			return this.workOrders && this.workOrders.length > 0;
		}
	},
	methods: {
		// 加载维修单列表
		async loadWorkOrders() {
			if (this.loading) return;
			
			this.loading = true;
			try {
				const res = await listWorkOrder({
					pageNum: 1,
					pageSize: 100
				});
				
				console.log('API响应:', res);
				
				if (res && res.code === 200 && res.rows && res.rows.length > 0) {
					// 获取用户角色进行不同的过滤
					const userInfo = getUserInfo();
					const roleKey = permissionManager.getRoleKey();
					console.log('当前用户角色:', roleKey);
					
					// 根据角色进行不同的过滤
					let filteredRows = res.rows;
					if (roleKey === 'maintenance_manager') {
						// 维修主管：过滤掉待确认状态
						filteredRows = res.rows.filter(item => item.statusCode !== 'PENDING_CONFIRM');
						console.log('维修主管：过滤掉待确认状态');
					} else if (roleKey === 'maintenance_foreman') {
						// 维修工长：过滤掉待指派状态
						filteredRows = res.rows.filter(item => item.statusCode !== 'PENDING_ASSIGN');
						console.log('维修工长：过滤掉待指派状态');
					}
					
					// 映射数据
					const newData = filteredRows.map((item, index) => ({
						id: item.workNo || index,
						workNo: item.workNo,
						reportNo: item.rptNo,
						startTime: item.startTime || '',
						endTime: item.endTime || '',
						status: item.statusCode,
						statusName: this.getStatusName(item.statusCode),
						assigneeId: item.assigneeId
					}));
					
					console.log('处理后的数据（已按角色过滤）:', newData);
					console.log('数据长度:', newData.length);
					
				// 使用Vue.set确保响应式
				this.$set(this, 'workOrders', newData);
				this.workOrdersLength = newData.length;
				
				console.log('设置后的数据:', this.workOrders);
				console.log('设置后的长度:', this.workOrders.length);
				console.log('workOrdersLength:', this.workOrdersLength);
				
				// 多次强制更新确保渲染
				this.$forceUpdate();
				setTimeout(() => {
					this.$forceUpdate();
				}, 100);
				} else {
					this.$set(this, 'workOrders', []);
					this.workOrdersLength = 0;
					console.log('没有数据，设置为空数组');
				}
			} catch (error) {
				console.error('加载维修单列表失败:', error);
				uni.showToast({
					title: '加载失败',
					icon: 'none'
				});
			} finally {
				this.loading = false;
			}
		},
		
		// 加载维修人员列表
		async loadWorkers() {
			try {
				console.log('开始加载维修人员列表...');
				
				// 直接使用uni.request调用API，与前台保持一致
				const token = uni.getStorageSync('token');
				const res = await uni.request({
					url: 'http://127.0.0.1:8081/system/role/authUser/allocatedList',
					method: 'GET',
					header: {
						'Content-Type': 'application/json',
						'Authorization': `Bearer ${token}`
					},
					data: {
						pageNum: 1,
						pageSize: 200,
						roleId: 4  // 维修人员角色ID
					}
				});
				
				console.log('维修人员API响应:', res);
				
				// uni.request返回的是数组格式 [error, response]
				const [error, response] = res;
				
				if (error) {
					console.error('API调用失败:', error);
					uni.showToast({
						title: '加载维修人员失败: ' + error.errMsg,
						icon: 'none'
					});
					return;
				}
				
				if (response && response.data && response.data.code === 200 && response.data.rows) {
					this.workers = response.data.rows.map(user => ({
						id: user.userId,
						name: user.nickName || user.userName
					}));
					
					console.log('维修人员列表加载成功，共', this.workers.length, '人');
					console.log('维修人员数据:', this.workers);
				} else {
					console.error('加载维修人员失败，响应:', response);
					uni.showToast({
						title: '加载维修人员失败: ' + (response?.data?.msg || '未知错误'),
						icon: 'none'
					});
				}
			} catch (error) {
				console.error('加载维修人员异常:', error);
				uni.showToast({
					title: '加载维修人员失败: ' + error.message,
					icon: 'none'
				});
			}
		},
			
        // 预加载维修单状态字典并缓存为Map，避免在渲染时异步
        async loadWorkOrderStatusDict() {
            try {
                const res = await uni.request({
                    url: 'http://127.0.0.1:8081/system/status/work-order/list',
                    method: 'GET',
                    header: {
                        'Content-Type': 'application/json',
                        'Authorization': `Bearer ${uni.getStorageSync('token')}`
                    },
                    data: { pageNum: 1, pageSize: 9999, enabled: 1 }
                });
                const list = (res.data && (res.data.rows || res.data.data)) || [];
                this._workStatusMap = {};
                list.forEach(it => { if (it && it.code) this._workStatusMap[it.code] = it.name; });
            } catch (e) {
                this._workStatusMap = {};
            }
        },
        // 同步获取状态名称（优先字典缓存，其次兜底）
        getStatusName(statusCode) {
            if (this._workStatusMap && this._workStatusMap[statusCode]) return this._workStatusMap[statusCode];
            return this.getFallbackStatusName(statusCode);
        },
		
		// 兜底状态名称
		getFallbackStatusName(statusCode) {
			const statusMap = {
				'PENDING_ASSIGN': '待分配',
				'ASSIGNED': '已指派',
				'PENDING_EXEC': '待维修',
				'IN_PROGRESS': '维修中',
				'PENDING_CONFIRM': '待确认',
				'CONFIRMED': '已确认',
				'DONE': '已完成',
				'CLOSED': '已关闭'
			};
			return statusMap[statusCode] || statusCode;
		},
			
		getStatusClass(status) {
			// 支持状态码和中文名称
			const classMap = {
				// 状态码
				'PENDING_ASSIGN': 'status-pending',
				'ASSIGNED': 'status-assigned',
				'IN_PROGRESS': 'status-processing',
				'CONFIRMED': 'status-completed',
				'COMPLETED': 'status-completed',
				'CANCELLED': 'status-default',
				// 中文名称
				'待分配': 'status-pending',
				'已指派': 'status-assigned',
				'待维修': 'status-pending',
				'维修中': 'status-processing',
				'待确认': 'status-pending',
				'已确认': 'status-completed',
				'已完成': 'status-completed',
				'进行中': 'status-processing'
			};
			return classMap[status] || 'status-default';
		},
		
		// 通过索引获取订单并查看
		viewOrderByIndex(index) {
			const order = this.workOrders[index];
			if (order) {
				this.viewOrder(order, index);
			} else {
				console.error('viewOrderByIndex: 无效的索引', index);
				uni.showToast({
					title: '数据错误',
					icon: 'none'
				});
			}
		},
		
		// 通过索引获取订单并指派
		assignWorkerByIndex(index) {
			const order = this.workOrders[index];
			if (order) {
				this.assignWorker(order, index);
			} else {
				console.error('assignWorkerByIndex: 无效的索引', index);
				uni.showToast({
					title: '数据错误',
					icon: 'none'
				});
			}
		},
		
		// 通过索引获取订单并删除
		deleteOrderByIndex(index) {
			const order = this.workOrders[index];
			if (order) {
				this.deleteOrder(order, index);
			} else {
				console.error('deleteOrderByIndex: 无效的索引', index);
				uni.showToast({
					title: '数据错误',
					icon: 'none'
				});
			}
		},
		
		// 通过索引获取订单并确认
		confirmOrderByIndex(index) {
			const order = this.workOrders[index];
			if (order) {
				this.confirmOrder(order, index);
			} else {
				console.error('confirmOrderByIndex: 无效的索引', index);
				uni.showToast({
					title: '数据错误',
					icon: 'none'
				});
			}
		},
		
		// 通过索引获取订单并拒绝确认
		rejectConfirmByIndex(index) {
			const order = this.workOrders[index];
			if (order) {
				this.rejectConfirm(order, index);
			} else {
				console.error('rejectConfirmByIndex: 无效的索引', index);
				uni.showToast({
					title: '数据错误',
					icon: 'none'
				});
			}
		},
			
		async viewOrder(order, index) {
				// 检查参数是否有效
				if (!order || !order.workNo) {
					console.error('viewOrder: 无效的order参数', order, 'index:', index);
					uni.showToast({
						title: '数据错误',
						icon: 'none'
					});
					return;
				}
				
				try {
					uni.showLoading({ title: '加载详情...' });
					
					// 从后端获取维修单详情
					const res = await getWorkOrder(order.workNo);
					
					uni.hideLoading();
					
					if (res && res.code === 200 && res.data) {
						// 使用后端返回的详细数据
						this.currentOrder = {
							...order,
							...res.data,
							// 确保显示名称正确
							statusName: res.data.statusName || this.getStatusName(res.data.statusCode) || order.statusName
						};
						this.showDetailModal = true;
					} else {
						// 如果后端没有详情，使用列表数据
						this.currentOrder = order;
						this.showDetailModal = true;
						uni.showToast({
							title: '获取详情失败，显示基本信息',
							icon: 'none'
						});
					}
				} catch (error) {
					uni.hideLoading();
					console.error('获取维修单详情失败:', error);
					
					// 出错时使用列表数据
					this.currentOrder = order;
					this.showDetailModal = true;
					
					uni.showToast({
						title: '获取详情失败，显示基本信息',
						icon: 'none'
					});
				}
			},
			
			assignWorker(order, index) {
				this.currentOrder = order;
				this.selectedWorker = '';
				this.selectedWorkerId = null;
				this.workerIndex = 0;
				this.showAssignModal = true;
				// 确保加载维修人员列表
				this.loadWorkers();
			},
			
			closeAssignModal() {
				this.showAssignModal = false;
				this.selectedWorker = '';
				this.selectedWorkerId = null;
				this.workerIndex = 0;
			},
			
			closeDetailModal() {
				this.showDetailModal = false;
				this.currentOrder = {};
			},
			
			onWorkerChange(e) {
				this.workerIndex = e.detail.value;
				this.selectedWorker = this.workers[e.detail.value].name;
				this.selectedWorkerId = this.workers[e.detail.value].id;
			},
			
			async confirmAssign() {
				if (!this.selectedWorker || !this.selectedWorkerId) {
					uni.showToast({
						title: '请选择维修人员',
						icon: 'none'
					});
					return;
				}
				
				try {
					uni.showLoading({ title: '指派中...' });
					
					// 调用后端API更新维修单
					const updateData = {
						workNo: this.currentOrder.workNo,
						assigneeId: this.selectedWorkerId,
						statusCode: 'ASSIGNED' // 更新状态为已指派
					};
					
					const res = await updateWorkOrder(updateData);
					
					uni.hideLoading();
					
					if (res && res.code === 200) {
						uni.showToast({
							title: '指派成功',
							icon: 'success'
						});
						
						// 更新列表中的数据
						const index = this.workOrders.findIndex(o => o.workNo === this.currentOrder.workNo);
						if (index !== -1) {
							this.workOrders[index].status = 'ASSIGNED';
							this.workOrders[index].statusName = '已指派';
							this.workOrders[index].assigneeId = this.selectedWorkerId;
						}
						
						this.closeAssignModal();
					} else {
						uni.showToast({
							title: res.msg || '指派失败',
							icon: 'none'
						});
					}
				} catch (error) {
					uni.hideLoading();
					console.error('指派失败:', error);
					
					const errorMsg = error.msg || error.message || '指派失败';
					uni.showToast({
						title: errorMsg,
						icon: 'none'
					});
				}
			},
			
			async deleteOrder(order, index) {
				uni.showModal({
					title: '确认删除',
					content: `确定要删除维修单"${order.workNo}"吗？删除后将无法恢复。`,
					success: async (res) => {
						if (res.confirm) {
							try {
								uni.showLoading({ title: '删除中...' });
								
								// 调用后端API删除维修单
								const deleteRes = await delWorkOrder(order.workNo);
								
								uni.hideLoading();
								
								if (deleteRes && deleteRes.code === 200) {
									uni.showToast({
										title: '删除成功',
										icon: 'success'
									});
									
								// 从列表中移除
								const index = this.workOrders.findIndex(o => o.workNo === order.workNo);
								if (index !== -1) {
									this.workOrders.splice(index, 1);
									this.workOrdersLength = this.workOrders.length;
								}
								} else {
									uni.showToast({
										title: deleteRes.msg || '删除失败',
										icon: 'none'
									});
								}
							} catch (error) {
								uni.hideLoading();
								console.error('删除失败:', error);
								
								const errorMsg = error.msg || error.message || '删除失败';
								uni.showToast({
									title: errorMsg,
									icon: 'none'
								});
							}
						}
					}
				});
			},
			
			// 确认维修单
			async confirmOrder(order, index) {
				uni.showModal({
					title: '确认维修单',
					content: `确定要确认维修单"${order.workNo}"吗？确认后将完成维修流程。`,
					success: async (res) => {
						if (res.confirm) {
							try {
								uni.showLoading({ title: '确认中...' });
								
								// 调用后端API确认维修单，设置为已确认状态
								const confirmRes = await updateWorkOrder({
									workNo: order.workNo,
									statusCode: 'CONFIRMED',
									rptNo: order.reportNo  // 使用正确的字段名，确保状态同步
								});
								
								uni.hideLoading();
								
								if (confirmRes && confirmRes.code === 200) {
									uni.showToast({
										title: '确认成功',
										icon: 'success'
									});
									
									// 更新列表中的状态
									const orderIndex = this.workOrders.findIndex(o => o.workNo === order.workNo);
									if (orderIndex !== -1) {
										this.workOrders[orderIndex].status = 'CONFIRMED';
										this.workOrders[orderIndex].statusCode = 'CONFIRMED';
										this.workOrders[orderIndex].statusName = '已确认';
									}
								} else {
									uni.showToast({
										title: confirmRes.msg || '确认失败',
										icon: 'none'
									});
								}
							} catch (error) {
								uni.hideLoading();
								console.error('确认失败:', error);
								
								const errorMsg = error.msg || error.message || '确认失败';
								uni.showToast({
									title: errorMsg,
									icon: 'none'
								});
							}
						}
					}
				});
			},
			
			// 拒绝确认维修单
			async rejectConfirm(order, index) {
				uni.showModal({
					title: '拒绝确认',
					content: `确定要拒绝确认维修单"${order.workNo}"吗？拒绝后将重新分配给维修员。`,
					success: async (res) => {
						if (res.confirm) {
							try {
								uni.showLoading({ title: '拒绝确认中...' });
								
								// 调用后端拒绝确认接口，逻辑与拒绝承认一致
								const rejectRes = await uni.request({
									url: `${this.baseUrl}/system/order/reject/${order.workNo}`,
									method: 'PUT',
									header: {
										'Authorization': `Bearer ${uni.getStorageSync('token')}`
									}
								});
								
								uni.hideLoading();
								
								if (rejectRes.data && rejectRes.data.code === 200) {
									uni.showToast({
										title: '拒绝确认成功，已重新分配',
										icon: 'success'
									});
									
									// 从列表中移除该维修单，因为已重新分配
									this.workOrders.splice(index, 1);
								} else {
									uni.showToast({
										title: rejectRes.data?.msg || '拒绝确认失败',
										icon: 'none'
									});
								}
							} catch (error) {
								uni.hideLoading();
								console.error('拒绝确认失败:', error);
								
								const errorMsg = error.msg || error.message || '拒绝确认失败';
								uni.showToast({
									title: errorMsg,
									icon: 'none'
								});
							}
						}
					}
				});
			},
			
			// 返回上一页
			goBack() {
				uni.navigateBack();
			}
		}
	}
</script>

<style scoped>
.container {
	min-height: 100vh;
	background-color: #f5f5f5;
}

.status-bar {
	height: 44px;
	background-color: #4a94ff;
}

/* 头部 */
.header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 44px;
	background-color: #4a94ff;
	padding: 0 16px;
	position: relative;
}

.header-left {
	width: 60px;
	display: flex;
	align-items: center;
}

.back-icon {
	font-size: 24px;
	color: white;
	font-weight: bold;
}

.header-title {
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	font-size: 18px;
	font-weight: bold;
	color: white;
}

.header-right {
	width: 60px;
}

/* 维修单列表 */
.work-orders-list {
	padding: 12px 16px;
	min-height: 200px;
	background-color: #f5f5f5;
}

.work-order-item {
	background-color: #fff;
	border-radius: 8px;
	padding: 16px;
	margin-bottom: 12px;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.order-header {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	margin-bottom: 12px;
	padding-bottom: 12px;
	border-bottom: 1px solid #f0f0f0;
}

.order-info {
	flex: 1;
}

.order-no {
	display: block;
	font-size: 14px;
	font-weight: bold;
	color: #333;
	margin-bottom: 4px;
}

.report-no {
	display: block;
	font-size: 12px;
	color: #666;
}

.status-badge {
	padding: 4px 12px;
	border-radius: 12px;
	font-size: 12px;
}

.status-badge.status-pending {
	background-color: #fff3e0;
	color: #ff9800;
}

.status-badge.status-assigned {
	background-color: #e1f5fe;
	color: #0288d1;
}

.status-badge.status-completed {
	background-color: #e8f5e8;
	color: #4caf50;
}

.status-badge.status-processing {
	background-color: #e3f2fd;
	color: #2196f3;
}

.status-badge.status-default {
	background-color: #f5f5f5;
	color: #999;
}

.order-detail {
	display: flex;
	justify-content: space-between;
	font-size: 14px;
	color: #666;
	margin-bottom: 8px;
}

.detail-label {
	font-weight: 500;
}

.order-actions {
	display: flex;
	gap: 8px;
	margin-top: 12px;
}

.action-btn {
	flex: 1;
	height: 36px;
	font-size: 14px;
	border-radius: 6px;
	border: none;
}

.action-btn.view {
	background-color: #409eff;
	color: white;
}

.action-btn.assign {
	background-color: #67c23a;
	color: white;
}

.action-btn.delete {
	background-color: #f56c6c;
	color: white;
}

/* 空状态 */
.empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 60px 0;
}

.empty-icon {
	font-size: 64px;
	margin-bottom: 16px;
}

.empty-text {
	font-size: 14px;
	color: #999;
}

/* 加载状态 */
.loading-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 60px 0;
}

.loading-text {
	font-size: 14px;
	color: #999;
}

/* 弹窗 */
.modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.5);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 9999;
}

.modal-content {
	width: 80%;
	background-color: white;
	border-radius: 12px;
	overflow: hidden;
}

.modal-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 16px;
	border-bottom: 1px solid #f0f0f0;
}

.modal-title {
	font-size: 16px;
	font-weight: bold;
	color: #333;
}

.modal-close {
	font-size: 24px;
	color: #999;
}

.modal-body {
	padding: 16px;
}

.form-item {
	margin-bottom: 16px;
}

.form-label {
	display: block;
	font-size: 14px;
	color: #666;
	margin-bottom: 8px;
}

.required {
	color: #f56c6c;
}

.form-value {
	font-size: 14px;
	color: #333;
}

.picker {
	border: 1px solid #dcdfe6;
	border-radius: 4px;
	padding: 10px;
	background-color: #fff;
}

.picker-text {
	font-size: 14px;
	color: #333;
}

.modal-footer {
	display: flex;
	border-top: 1px solid #f0f0f0;
}

.modal-btn {
	flex: 1;
	height: 48px;
	font-size: 16px;
	border: none;
	border-radius: 0;
}

.modal-btn.cancel {
	background-color: #f5f5f5;
	color: #666;
}

.modal-btn.confirm {
	background-color: #409eff;
	color: white;
}
</style>

